<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 *  RadioDJ
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage radiodj
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/RadioDJ
 */ 

/**
 *  Dymanic Tag wich outputs song
 *  Format: #SONG{<song_number>}
 *          <song_number>: 0 - Current song, 1-5 - Previous songs 
 */

function balise_RADIODJ_SONG($p) {	
	return calculer_balise_dynamique($p,'RADIODJ_SONG', array());
}

function balise_RADIODJ_SONG_stat($args, $filtres) {    
	return $args;
}

/**
 *  This function contain XML file parser (wich you may change according to your purposes)
 *  @param string $song_type Song type. Variants: 
 *                                      'playing' - Current song (will be updated via AJAX)
 *   
 */ 
function balise_RADIODJ_SONG_dyn($song_num = 0) {
	// Read file contents only once
	static $last_songs;
	if (!isset($last_songs) || !$last_songs)
		$last_songs = unserialize(file_get_contents(_DIR_PLUGIN_RADIODJ.'last_songs.txt'));
   
   if (isset($last_songs[$song_num])) {
        $song_name = $last_songs[$song_num]['NAME'];
        $song_artist = $last_songs[$song_num]['ARTIST'];
        $song_start_time = $last_songs[$song_num]['START_TIME'];
        $song_start_date = $last_songs[$song_num]['START_DATE'];
        $song_duration = $last_songs[$song_num]['DURATION'];
   }

   $update_time = lire_config('radiodj/SongsReloadTime');
   $update_time = $update_time ? $update_time : 30;
   
    return array('balise/radiodj_song', $update_time,
		array(
            'song_num'=>$song_num,
            'name'=> $song_name,
            'artist'=> $song_artist
		));
}

?>